package cn.attackme.myuploader.controller;


import cn.attackme.myuploader.model.Plot_coordinate;
import cn.attackme.myuploader.service.Plot_coordinateService;
import cn.attackme.myuploader.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/plot")
@CrossOrigin
public class Plot_coordinateController {
    @Autowired
    private Plot_coordinateService plot_coordinateService;
    @PostMapping("/coordinate")
    public Map<String,Object> coordinate(int id) throws IOException {
        System.out.println(id);
        Plot_coordinate plot_coordinate=plot_coordinateService.getcoordinate(id);
        Map<String,Object> resultMap = ResultUtils.getResponse(plot_coordinate,"succeed",
                "internal error",false);
        return resultMap;
    }

    @PostMapping("/addcoordinate")
    public Map<String,Object> addcoordinate(Plot_coordinate plot_coordinate) throws IOException {
        System.out.println(plot_coordinate);
        int  flag =plot_coordinateService.save(plot_coordinate);
        Map<String,Object> resultMap = ResultUtils.getResponse(flag,"succeed",
                "internal error",false);
        return resultMap;
    }

    @PostMapping("/updatecoordinate")
    public Map<String,Object> updatecoordinate(Plot_coordinate plot_coordinate) throws IOException {
        System.out.println(plot_coordinate);
        int  flag =plot_coordinateService.update(plot_coordinate);
        Map<String,Object> resultMap = ResultUtils.getResponse(flag,"succeed",
                "internal error",false);
        return resultMap;
    }

    @PostMapping("/deletecoordinate")
    public Map<String,Object> deletecoordinate(int id) throws IOException {
        int  flag =plot_coordinateService.deleteById(id);
        Map<String,Object> resultMap = ResultUtils.getResponse(flag,"succeed",
                "internal error",false);
        return resultMap;
    }

    @PostMapping("/all")
    public Map<String,Object> all() throws IOException {

        List<Map<String,Object>> allList= plot_coordinateService.allList();
        Map<String,Object> resultMap = ResultUtils.getResponse(allList,"succeed",
                "internal error",false);
        return resultMap;
    }



}
